package api

import (
	"iris-starter/pkg/errno"

	"github.com/kataras/iris/v12"
)

type Response struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

func JsonResponse(ctx iris.Context, err error, data interface{}) {
	code, msg := errno.DecodeErr(err)
	_, _ = ctx.JSON(Response{
		Code:    code,
		Message: msg,
		Data:    data,
	})
}
